<?php
/**
 * @see Phorm_JQuery_View_Helper_Multi
 */
require_once "Phorm/JQuery/View/Helper/Multi.php";

/**
 * Помощник вида, реализующий добавление множественных текстовых полей (например, для списка тегов)
 * 
 * @category Phorm
 * @package JQuery_View_Helper
 * @name /Phorm/JQuery/View/Helper/MultiText.php
 * @copyright phorm.ru
 * @since 29.01.2011
 * @author vladimir@kachalov.net
 */

class Phorm_JQuery_View_Helper_MultiText extends Phorm_JQuery_View_Helper_Multi {
	
	/**
	 * Рисуем элемент формы
	 *
	 * @param string $id Id HTML-элемента
	 * @param string $value Значение элемента
	 * @param array $params Массив параметров элемента
	 * @param array $attribs Массив атрибутов HTML-элемента
	 * @return string
	 */
    
	public function multiText($id, $value = null, $params = array(), $attribs = array()) {
		
		$attribs = is_array($attribs) ? $attribs : array();
		
		return $this->initElement($id,$value,$params,$attribs)->getXHTML();
		
	}
	
	
	/**
	 * Возвращает HTML-код элемента
	 *
	 * @return string
	 */
	
	protected function getXHTML() {
		
		$attribs = array();
	    foreach ($this->_attribs as $k=>$v) if(in_array($k,array('class','style'))) $attribs[$k] = $v;
		
		$xhtml = $this->view->Button($this->_buttonid, $this->view->escape($this->_params['button']));
		
		$xhtml .= '<ul id="'.$this->_ulid.'" class="' . $this->_class . '">' . PHP_EOL;
		
		foreach ($this->_options as $fieldid=>$fieldvalue) {
			
			if(!empty($fieldvalue)) {
        	
	        	$xhtml .= '<li' . $this->_htmlAttribs($attribs) . '>' . 
	        					$this->view->formText($this->_name . '[' . $fieldid . ']', $this->view->escape($fieldvalue),$this->_elementattribs) . 
	        			  		'&nbsp;' . $this->_deleteimg . 
	        			  '</li>' . PHP_EOL;
        			  
			}
        	
        }
        
        $attribs['class'] .= isset($attribs['class']) ? ' hidden' : '';
        
        $xhtml .= '<li' . $this->_htmlAttribs($attribs) . '>' . 
        				$this->view->formText($this->_id,null,$this->_elementattribs+array('disabled'=>'disabled')) . 
        				'&nbsp;' . $this->_deleteimg .
        		  '</li>' . PHP_EOL;
        
        $xhtml .= '</ul>' . PHP_EOL;
        
        return $xhtml;
		
	}
	
}